package com.kedacom.freedomLabel.initdata.dao;

import android.arch.persistence.room.Dao;
import android.arch.persistence.room.Delete;
import android.arch.persistence.room.Insert;
import android.arch.persistence.room.OnConflictStrategy;
import android.arch.persistence.room.Query;
import android.arch.persistence.room.Update;

import com.kedacom.freedomLabel.initdata.bean.Post;
import com.kedacom.freedomLabel.initdata.bean.RubbishBean;
import com.kedacom.freedomLabel.model.bean.ProductCount;
import com.kedacom.freedomLabel.model.db.dao.IDao;

import java.util.List;


/**
 * Created by yao on 2021/3/23.
 * Describe
 */

@Dao
public interface RubbishDao extends IDao<RubbishBean> {

    @Override
    @Query("SELECT COUNT(0) FROM Post")
    int count();

    @Override
    @Update
    void update(RubbishBean data);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long save(RubbishBean data);

    @Override
    @Insert(onConflict = OnConflictStrategy.FAIL)
    long[] save(List<RubbishBean> data);

    @Override
    @Query("SELECT * FROM RubbishBean ORDER BY id")
    List<RubbishBean> get();

    @Override
    @Query("SELECT * FROM RubbishBean WHERE category=:param")
    List<RubbishBean> get(String param);


    @Query("SELECT * FROM RubbishBean WHERE weighingTime >=:startTime order by weighingTime DESC")
    List<RubbishBean> getRubbishWithStartTime(long startTime);



    @Query("SELECT * FROM RubbishBean WHERE weighingTime >=:startTime  AND weighingTime<:endTime order by weighingTime DESC")
    List<RubbishBean> getOneDayPost(long startTime, long endTime);

    @Query("DELETE FROM RubbishBean WHERE weighingTime >=:startTime")
    void deleteWithStartTime(long startTime);


    @Query("DELETE  FROM RubbishBean WHERE weighingTime >=:startTime  AND weighingTime<:endTime")
    void deleteOneDayPost(long startTime, long endTime);


    @Query("SELECT COUNT(*) as number,SUM(weight) as weight FROM RubbishBean WHERE weighingTime>=:startTime")
    ProductCount getBusiness(long startTime);


    @Override
    @Query("SELECT * FROM RubbishBean WHERE id=:param1 and id LIKE :param2")
    List<RubbishBean> get(String param1, String param2);

    @Override
    @Delete
    void delete(RubbishBean data);

    @Override
    @Query("DELETE FROM RubbishBean")
    void delete();

    @Override
    @Query("DELETE FROM RubbishBean WHERE id=:param ")
    void delete(String param);


}